package com.lagou.homework;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;

/**
 * 自定义Mapper继承Mapper类, 输入类型是文件中中的一行行数据, 所以输入类型使用LongWritable, Text
 * 因为涉及到排序, 所以自定义bean类, 输出键的值. 输出类型: NumberBean, NullWritable
 */
public class NumberMapper extends Mapper<LongWritable, Text, NumberBean, NullWritable> {

    private NumberBean bean = new NumberBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //获取一行输入
        String number = value.toString();
        //设置bean类的值为读取的行的数字
        bean.setNumber(Integer.parseInt(number));
        //输出
        context.write(bean, NullWritable.get());
    }
}
